package tmproject.hlhj.fhp.cartrans.http

import android.content.Context
import android.content.Intent
import io.reactivex.disposables.Disposable
import tmproject.hlhj.fhp.cartrans.BaseAty
import tmproject.hlhj.fhp.cartrans.BaseFgm
import tmproject.hlhj.fhp.cartrans.activitys.LoginAty
import tmproject.hlhj.fhp.cartrans.convert.MyException
import tmproject.hlhj.fhp.cartrans.utils.SpHelper

/**
 * Created by Never Fear   on 2018\9\1 0001.
Never More....
 */
abstract class BaseObserver<T>(private val c:Context) :BaseAciton<T>{

    override fun httpFailed(e: Throwable?) {
        if ( e is MyException){
            if (e.code==500){
                SpHelper.saveToken(c,"")
                c.startActivity(Intent(c,LoginAty::class.java))
            }
        }
        failed(e)
    }

    override fun onSubscribe(d: Disposable) {
        if (c is BaseAty<*,*>){
            c.addDisable(d)
        }
    }
    abstract fun failed(e:Throwable?)
    override fun onError(e: Throwable) {
        super.onError(e)
    }

}